# -*- encoding:utf-8 -*-
# __author__ = 'chenyongbing'
# __poject__ = 'ops_platform'
# __datetime__ = '2022/6/13'
# __name__ = 'filters.py'
from django_filters.rest_framework import FilterSet
import django_filters

from .models import *
# Create your code here.


class GitCommitFilter(FilterSet):
    """
    支持模糊搜索
    icontains，包含且忽略大小写
    """
    committer = django_filters.CharFilter(field_name='committer', lookup_expr='icontains')
    # start = django_filters.DateFilter(field_name='committed_date', lookup_expr='gte')
    # end = django_filters.DateFilter(field_name='committed_date', lookup_expr='lte')
    committed_date = django_filters.DateFromToRangeFilter()
    class Meta:
        # 指定模型
        models = GitCommit
        # 指定需要模糊查询的字段
        # fields = ['committer', 'start', 'end']
        fields = ['committer', 'committed_date']


class GitCommitDayStatFilter(FilterSet):
    committer = django_filters.CharFilter(field_name='committer', lookup_expr='icontains')
    date = django_filters.DateFilter(field_name='date', lookup_expr='gte')

    class Meta:
        # 指定模型
        models = GitCommit
        # 指定需要模糊查询的字段
        fields = ['committer', 'date']

        